﻿#include<stdio.h>
#include<stdlib.h>
struct ListNode
{
	int val;
	struct ListNode* next;
};
int kthToLast(struct ListNode* head, int k)
{
	struct ListNode* fast = head, * slow = head;
	while (k--)
	{
		fast = fast->next;
	}
	while (fast)
	{
		fast = fast->next;
		slow = slow->next;
	}
	return slow->val;
}
int main()
{
	int k = 2;
	struct ListNode* head = (struct ListNode*)malloc(sizeof(struct ListNode));
	head->val = 1;
	struct ListNode* node1 = (struct ListNode*)malloc(sizeof(struct ListNode));
	node1->val = 2;
	struct ListNode* node2 = (struct ListNode*)malloc(sizeof(struct ListNode));
	node2->val = 3;
	struct ListNode* node3 = (struct ListNode*)malloc(sizeof(struct ListNode));
	node3->val = 4;
	struct ListNode* node4 = (struct ListNode*)malloc(sizeof(struct ListNode));
	node4->val = 5;
	head->next = node1;
	node1->next = node2;
	node2->next = node3;
	node3->next = node4;
	node4->next = NULL;
	int ret = kthToLast(head, k);
	printf("%d", ret);
	return 0;
}
